import Vue from 'vue'
import App from './App.vue'
import router from './router'

import axios from 'axios';
//引入ui库
import ElementUI from 'element-ui'
//引入css
import 'element-ui/lib/theme-chalk/index.css';
//注册组件库
Vue.use(ElementUI);

//添加图片过滤器
Vue.filter('fixImgUrl', (oldUrl) => {
  if (oldUrl.indexOf('http') > -1) {
    return oldUrl
  } else {
    return axios.defaults.baseURL + oldUrl;
  }
})


//绑定原型
Vue.prototype.$axios = axios;
//设置默认api域名基准路径
// axios.defaults.baseURL = 'http://127.0.0.1:3000'
axios.defaults.baseURL = 'http://liangwei.tech:3000'

//添加拦截器
axios.interceptors.request.use(config => {
  if (!config.headers.Authorization && localStorage.getItem('token')) {
    config.headers.Authorization = localStorage.getItem('token')
  }
  //拦截要记得放行
  return config
})

Vue.config.productionTip = false
new Vue({
  router,
  render: function (h) { return h(App) }
}).$mount('#app')


